<?php 

 class Former extends CI_Controller{
    function __construct(){
        parent::__construct();
		$this->load->library(array('session','pagination'));
		$this->load->helper('url');
		$this->load->database();
		
    }
	 
	/*
	*
	*
	*兄弟我们该出发了
	*启程
	*
	*
	*
	*/
/* 	function index(){
		$this->load->model('formermodel');
		$data['category']=$this->formermodel->get_category();
		$data['articlelist']=$this->formermodel->get_article();
		$this->load->view('former/index',$data);

	} */
	function index(){
		$this->load->model('formermodel');
		$data['category']=$this->formermodel->get_category();
		
		
		//
		$config['base_url']=site_url("former/index");
		$config['total_rows']=$this->formermodel->get_article_totalrows();
		$config['num_links']='3';
		$config['uri_segment']='3';
		$config['per_page']='5';
		$config['first_link']='首页';
		$config['last_link']='末页';
		$config['next_link']='>>';//后一页
		$config['prev_link']='<<';//前一页
		$config['cur_tag_open'] = ' <a class="on">'; // 当前页开始样式   
		$config['cur_tag_close'] = '</a>'; 
		$this->pagination->initialize($config);
		$data['links']=$this->pagination->create_links();
		//
		
		
		$data['articlelist']=$this->formermodel->get_article($this->uri->segment(3,0),$config['per_page']);
		$data['hotarticle']=$this->formermodel->get_hot_article();
		$data['randarticle']=$this->formermodel->get_rand_article();
		$this->load->view('former/index',$data);

	}
	
	
	
	
	/*
    *
	*
	*文章操作
	*
	*
	*/
/* 	function get_article(){
		$this->load->model('formermodel');
		$data['category']=$this->formermodel->get_category();
		$data['articlelist']=$this->formermodel->get_article();
		$this->load->view('former/index',$data);
		
		
	} */
	function articlelist(){
		//$cid=$this->uri->segment(3);
		$this->load->model('formermodel');
		$data['category']=$this->formermodel->get_category();
		//$data['articlelist']=$this->formermodel->get_article_list();
		
		$data['cid']=$this->uri->segment(3);
		if($data['cid']==10){
				redirect("former/test5");//管理文件上传
		}
		//$this->load->model("formermodel");
		$config['base_url']=site_url("former/articlelist/".$data['cid']);
		$config['total_rows']=$this->formermodel->get_article_rows($data['cid']);
		$config['num_links']='3';
		$config['uri_segment']='4';
		$config['per_page']='5';
		$config['first_link']='首页';
		$config['last_link']='末页';
		$config['next_link']='>>';//后一页
		$config['prev_link']='<<';//前一页
		
		$config['cur_tag_open'] = ' <a class="on">'; // 当前页开始样式   
		$config['cur_tag_close'] = '</a>'; 
		
		$this->pagination->initialize($config);
		$data['links']=$this->pagination->create_links();
		$data['articlelist']=$this->formermodel->get_article_list($data['cid'],$this->uri->segment(4,0),$config['per_page']);
		$data['hotarticle']=$this->formermodel->get_hot_article();
		$data['randarticle']=$this->formermodel->get_rand_article();
		$this->load->view('former/main',$data);	
		$this->load->view("former/article/articlelist",$data);	
		$this->load->view('former/bottom');
		
		
		
		//$this->load->view('former/main',$data);	  //main 类似于top
		//$this->load->view('former/articlelist',$data);
		//$this->load->view('former/bottom');
		
		}
	
		function test5(){  //这个方法是涉及到 文件上传与分享
			$this->load->model('formermodel');
			$data['file']=$this->formermodel->getdownloadlist();
			$this->load->view('former/test',$data);
			
			
			
		}
	

	
	function read_article(){
		
		$data['cid']=$this->uri->segment(4);
		// if($data['cid']==" "){
			// $data['cid']=$cid;
		// }
		$id=$this->uri->segment(3);
		$this->load->model('formermodel');
		$data['list']=$this->formermodel->read_article();
		$data['hotarticle']=$this->formermodel->get_hot_article();
		$data['randarticle']=$this->formermodel->get_rand_article();
		$data['comment']=$this->formermodel->getcomment($id);
		$data['num']=$this->formermodel->getcomment_num($id);
		$data['category']=$this->formermodel->get_category();
		$this->load->view('former/main',$data);	
		$this->load->view('former/article/readarticle',$data);
	}
/* 	function test(){
		$this->load->model('formermodel');
		$data['list']=$this->formermodel->read_article();
		$data['category']=$this->formermodel->get_category();
		$data['articlelist']=$this->formermodel->get_article();
		$this->load->view('former/main',$data);	
		$this->load->view('former/info',$data);
		$this->load->view('former/bottom');
	} */
	
	function addcomment(){
	    $this->load->model('formermodel');
		$content=$this->input->post('content');
	    $a=$this->formermodel->addcomment($content);
		$id=$this->uri->segment(3);
		$cid=$this->uri->segment(4);
		
		//$this->read_article();
		redirect('former/read_article/'.$id.'/'.$cid);
		//$this->read_article($cid);
		//echo $a;
	
	
	}
	function search(){
	    $info=$this->input->post('sstxt');
		// echo empty($info);
		// exit;
		if(empty($info)||ctype_space($info)){   //ctype_space() 判断输入的内容是否全是空格
		redirect('Former/index');
		}else {
		$info=trim($info); //trim() 用于跳过字符串左右的空格
		$info1=str_replace("'",'m',$info);
		$info2=str_replace("/",'c',$info1);
/* 		$specialstr=array('/and/','/‘/');
		$replacements=array('m','m');
		$info=preg_replace($specialstr,$replacements,$info); */
		// $specialstr=array("'",'/');
		// $replacements=array('_','_');

		//$info=preg_replace($specialstr,$replacements,$info);
		
		
		
		
		$this->load->model('formermodel');
		$data['category']=$this->formermodel->get_category();
		$arr=$this->formermodel->search($info2);
		$data['hotarticle']=$this->formermodel->get_hot_article();
		$data['randarticle']=$this->formermodel->get_rand_article();
		$data['articlelist']=$arr;
		$data['info']=$info;
		$this->load->view('former/search_index',$data); 
		}

	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 }
























































?>